// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import {Desk} from "./disPlayConfig";
import {modules} from "../../engines/gameEngine";

const {ccclass, property} = cc._decorator;

@ccclass
export default class disFindItem extends cc.Component {

    @property(cc.Label)
    lbId: cc.Label = null;
    @property(cc.Label)
    lbName: cc.Label = null;
    @property(cc.Sprite)
    spIcon: cc.Sprite = null;

    // LIFE-CYCLE CALLBACKS:

    protected onLoad() {
    }

    protected start() {
        this.initView();
    }

    private m_data: Desk.DisplayItem = null;

    setId(id: string) {
        this.m_data = <Desk.DisplayItem>Desk.getDisPlayItemList(id);
    }

    private initView() {
        const {id, name, icon} = this.m_data;
        this.lbId.string = `[${id}]`;
        this.lbName.string = name;
        //
        icon && modules().uiControlModule.getFrameBundle().load(
            `preload/hallIcon/${icon}`,
            cc.SpriteFrame,
            (error, assets: cc.SpriteFrame) => {
                if (error) {
                    console.error('#405511 错误的icon', icon);
                    return;
                }
                this.spIcon.spriteFrame = assets;
            });
    }

    onBtnClick() {
        this.m_data.onClickEvent();
    }

    // update (dt) {}
}
